<template>
  <view>
    <view class="flex flex-row j-content a-item">请选择人员</view>
    <scroll-view class="scroll-view_H" scroll-y>
      <checkbox-group @change="checkboxChange">
        <label class="uni-list-cell uni-list-cell-pd flex flex-row" v-for="item in userList" :key="item.realName">
          <view>
            <checkbox :value="item.name" :checked="item.checked" />
          </view>
          <view>{{item.name}}</view>
        </label>
      </checkbox-group>
    </scroll-view>
    <view class="flex flex-row">
      <button size="mini" @click="emitUserList">确定</button>
    </view>
  </view>
</template>

<script>
import { getSysUserList } from '@/service/api/logistics'

export default {
  props:{
    params: {
      type: Object,
      detail: null
    }
  },
  name: "user",
  data(){
    return {
      selectUserList:[],
      userList: [],
      query:{
        page:1,
        size: 100,
        businessAttr: '',
        code: '',
      }
    }
  },
  created() {
    this.getUser()
  },
  methods: {
    getUser(){
      console.log(this.params)
      getSysUserList({...this.query,...this.params}).then(res=>{
      }).catch(err=>{this.userList = err.content})
    },
    checkboxChange(e){
      var items = this.userList,
          values = e.detail.value;
      for (var i = 0, lenI = items.length; i < lenI; ++i) {
        const item = items[i]
        if(values.includes(item.name)){
          this.$set(item,'checked',true)
        }else{
          this.$set(item,'checked',false)
        }
      }
    },
    emitUserList(){
      this.selectUserList = this.userList.filter(item=>item.checked === true)
      this.$emit('getuserlist',this.selectUserList)
    },

  }
}
</script>
<style scoped>
.scroll-view_H{
  height: 1000rpx;
}
</style>
